﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Demo
{
    public partial class DemoListView : Form
    {
        public DemoListView()
        {
            InitializeComponent();
        }

        private void DemoListView_Load(object sender, EventArgs e)
        {
            smallIconRadio.Checked = true;
            listView1.View = View.SmallIcon;
        }

        private void updateButton_Click(object sender, EventArgs e)
        {
            listView1.Items.Clear();

            for (int i = 0; i < smallImageList.Images.Count; i++)
            {
                ListViewItem item = new ListViewItem();

                item.Text = "Image - " + i.ToString();
                item.ImageIndex = i;
                listView1.Items.Add(item);
            }
        }

        private void smallIconRadio_CheckedChanged(object sender, EventArgs e)
        {
            if (smallIconRadio.Checked)
                listView1.View = View.SmallIcon;
        }

        private void largeIconRadio_CheckedChanged(object sender, EventArgs e)
        {
            if (largeIconRadio.Checked)
                listView1.View = View.LargeIcon;
        }

        private void titleRadio_CheckedChanged(object sender, EventArgs e)
        {
            if (titleRadio.Checked)
                listView1.View = View.Tile;
        }

        private void listRadio_CheckedChanged(object sender, EventArgs e)
        {
            if (listRadio.Checked)
                listView1.View = View.List;
        }

        private void showItemsButton_Click(object sender, EventArgs e)
        {
            string selectedText = "", selectedIndex = "";

            foreach (ListViewItem item in listView1.SelectedItems)
            {
                selectedText += item.Text + ", ";
            }

            foreach (var item in listView1.SelectedIndices)
                selectedIndex += item.ToString() + ", ";

            MessageBox.Show(selectedText + Environment.NewLine + selectedIndex);

        }
    }
}
